package com.robmayhew.jsc;

import junit.framework.TestCase;

/**
 * Created by IntelliJ IDEA.
 * User: Rob
 * Date: 7-May-2005
 * Time: 10:36:25 AM
 * To change this template use File | Settings | File Templates.
 */
public class JavaSrcTokenListTest
    extends TestCase
{
    public void testPositioning() throws Exception
    {
        String testWord = "simpleTest";
        JavaSrcTokenList list = new JavaSrcTokenList();
        list.breakUp(testWord,0,0,testWord,0);
        assertPosition("simple", list,0,0,6);
        assertPosition("test", list,1,6,10);
    }

    public void testEndWithPeriod()throws Exception
    {
        String testWord = "period.";
        JavaSrcTokenList list = new JavaSrcTokenList();
        list.breakUp(testWord,0,0,testWord,0);
        assertPosition("period", list,0,0,6);
    }

    public static void assertPosition(String word, JavaSrcTokenList list, int index, int start, int end)
        throws Exception
    {
        JavaSrcToken token = list.getToken(index);
        assertNotNull(word + " - Token not found for index " + index, token);
        assertEquals(word + " - Word not same", word, token.getToken());
        assertEquals(word+ " - Start wrong", start, token.start);
        assertEquals(word + " - End wrong", end, token.end);
    }
}
